#include "stm32f10x.h"
#include "Delay.h"
#include "SSD1306.h"
#include "DHT11.h"
#include "Fan.h"
#include "SignalLight.h"
#include "UsePins.h"

extern uint8_t DHTDat[4] = {0, 0, 0, 0};

void showDHT11()
{
  OLED_Clear();
  OLED_ShowCN(1, 1, 0, 1);
  OLED_ShowCN(1, 2, 1, 1);
  OLED_ShowString(1, 5, ":");
  OLED_ShowString(1, 9, ".");
  OLED_ShowString(1, 11, "^C");

  OLED_ShowCN(3, 1, 2, 1);
  OLED_ShowCN(3, 2, 3, 1);
  OLED_ShowString(3, 5, ":");
  OLED_ShowString(3, 9, ".");
  OLED_ShowString(3, 11, "%");
  if (Read_DHT11(DHTDat) == 1)
  {
  }
  else
  {
  }
  OLED_ShowNum(1, 7, DHTDat[2], 2);
  OLED_ShowNum(1, 10, DHTDat[3], 1);
  OLED_ShowNum(3, 7, DHTDat[0], 2);
  OLED_ShowNum(3, 10, DHTDat[1], 1);
}

int main(void)
{
  uint8_t i;
  uint8_t j;
  int temp;
  Light_Init();
  DHT11_Init();
  OLED_Init();
  while (1)
  {

    showDHT11();
    LightYellow(0);
    temp = (int)DHTDat[2];
    if (temp >= 30)
    {
      Fan_PWM_Init();
      for (i = 0; i <= 10; i++)
      {
        Fan_PWM_SetCompare(i);
        LightWarning(i);
      }
    }
    else
    {

      Green_Light_Init();

      for (i = 0; i <= 100; i++)
      {
        Light_PWM_SetCompare(i);
        Delay_ms(30);
      }

      for (j = 100; j > 0; j--)
      {
        Light_PWM_SetCompare(j);
        Delay_ms(30);
      }
    }
  }
}
